{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "# 字符串"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "source": [
    "1. 用来表示一段文本信息，字符串是程序中使用最多的数据类型\n",
    "2. 在 Python 中字符串需要用引号引起来\n",
    "3. 引号可以是 `\"` 也可以是 `'` ，但不要混着用"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s1 = \"hello\"\n",
    "s2 = 'world'\n",
    "print(s1)\n",
    "print(s2)"
   ]
  },
  {
   "source": [
    "4. 相同的引号之间不能嵌套"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = '子曰：\"学而时习之\"'\n",
    "print(s)"
   ]
  },
  {
   "source": [
    "5. 单引号和双引号不能跨行使用\n",
    "6. 三重引号可以换行，并且会保留字符串中的格式"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = '''锄禾日当午，\n",
    "汗滴禾下土。\n",
    "谁知盘中餐，\n",
    "粒粒皆辛苦。\n",
    "'''\n",
    "print(s)"
   ]
  },
  {
   "source": [
    "7. 通过转义字符可以在字符串中使用一些特殊的内容\n",
    "    - `\\` - 转义后面的字符\n",
    "    - `\\t` - 制表符\n",
    "    - `\\n` - 换行符\n",
    "    - `\\uxxxx` - Unicode 编码"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s1 = \"子曰：\\\"学而时习之，不亦乐乎？\\\"\"\n",
    "s2 = \"Hello\\nWorld\"\n",
    "s3 = \"\\\\t\"# 就想打印 /t\n",
    "s4 = \"\\u0021\"\n",
    "print(s1)\n",
    "print(s2)\n",
    "print(s3)\n",
    "print(s4)"
   ]
  }
 ]
}